package com.xuecheng.content.controller;


import com.xuecheng.api.content.TeachplanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.dto.TeachplanWorkDTO;
import com.xuecheng.api.content.model.vo.BindTeachplanMediaVO;
import com.xuecheng.api.content.model.vo.BindTeachplanWorkVO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.convert.TeachplanMediaConvert;
import com.xuecheng.content.convert.TeachplanWorkConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService teachplanService;


    @GetMapping("teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTreeNode(@PathVariable Long courseBaseId) {


        Long companyId = UAASecurityUtil.getCompanyId();

        return teachplanService.queryTreeNodes(courseBaseId, companyId);

    }

    @DeleteMapping("teachplan/{teachPlanId}")
    public boolean deleteTeachPlan(@PathVariable Long teachPlanId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        return teachplanService.deleteTeachPlan(teachPlanId, companyId);
    }

    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO teachplanVO) {

        Long companyId = UAASecurityUtil.getCompanyId();

        TeachplanDTO teachplanDTO = TeachplanConvert.INSTANCE.voToTeachPlanDTO(teachplanVO);

        return teachplanService.createOrModifyTeachPlan(teachplanDTO, companyId);
    }

    @PostMapping("teachplan/media/association")
    public TeachplanMediaDTO createOrModifyTeachplanMedia(@RequestBody BindTeachplanMediaVO teachplanMediaVO) {

        Long companyId = UAASecurityUtil.getCompanyId();

        TeachplanMediaDTO teachplanMediaDTO = TeachplanMediaConvert.INSTANCE.voToTeachplanMediaDTO(teachplanMediaVO);

        return teachplanService.createOrModifyTeachplanMedia(teachplanMediaDTO, companyId);
    }

    @PostMapping("teachplan/work/association")
    public TeachplanWorkDTO createOrModifyTeachplanWork(@RequestBody BindTeachplanWorkVO teachplanWorkVO) {

        Long companyId = UAASecurityUtil.getCompanyId();

        TeachplanWorkDTO teachplanWorkDTO = TeachplanWorkConvert.INSTANCE.voToTeachplanWorkDTO(teachplanWorkVO);

        return teachplanService.createOrModifyTeachplanWork(teachplanWorkDTO, companyId);
    }

    @DeleteMapping("teachplan/media/{teachplanMediaId}")
    public void removeTeachplanMedia(@PathVariable Long teachplanMediaId, Long courseBaseId) {
        Long companyId = UAASecurityUtil.getCompanyId();

        teachplanService.removeTeachplanMedia(teachplanMediaId, courseBaseId, companyId);

    }

    @DeleteMapping("teachplan/work/{teachplanWorkId}")
    public void removeTeachplanWork(@PathVariable Long teachplanWorkId, Long courseBaseId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        teachplanService.removeTeachplanWork(teachplanWorkId, courseBaseId, companyId);
    }




}
